<?php

class GeoController extends Controller
{
		
    private $client; 
	/*		
	function init()
	{
		ini_set('soap.wsdl_cache_enabled', '0'); 
		ini_set('soap.wsdl_cache_ttl', '0'); 
		parent::init();
	 	$this->client =  new SoapClient('http://services.pec-sg.ch/index.php/webservice/mask?wsdl',
			array('trace' => 1)
			);
		$auth = array(
        	'UserName'=>'Paul',
        	'Password'=> 'qaws'
        	);
  		$header = new SoapHeader('http://services.pec-sg.ch','Auth', $auth ,false);

  		$this->client->__setSoapHeaders($header);

	}
	*/
	/**
	 * @var CActiveRecord the currently loaded data model instance.
	 */
	private $_model;

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
		 */
	public function accessRules()
	{
		return array(
		);
	}
	public function actionCoordinates()
	{
	  	$val1 = $_POST['val1'];
  		$val2 = $_POST['val2'];
			if (1 ==1 ) { //(Yii::app()->request->isAjaxRequest) {
						$output = "".$val1;
						//$output .= $_POST['GeoForm']['street'];
			$coord=get_coordinates($_POST['GeoForm']['city'].','.$_POST['GeoForm']['street']);
    	$loc = get_location($coord['latitude'],$coord['longitude']);
		$loc = get_distance(10.4151544,48.4297427,$coord['latitude'],$coord['longitude']);

				$jsonIterator = new RecursiveIteratorIterator(
   					 new RecursiveArrayIterator(json_decode($loc, TRUE)),
    					RecursiveIteratorIterator::SELF_FIRST);

				foreach ($jsonIterator as $key => $val) {
					if(is_array($val)) {
						$output .= $key.": ";
					} else {
						$output .= $val. "<br />";
					}
				}

        	      $data = array();
        $data = array();
        $data["myValue"] = $output;
 
        $this->renderPartial('_view', $data, false, true);
}
				        	//echo 'the end II';
        	//
    }
    
/*
				foreach ( $loc->Placemark as $pm )
				{
    				echo "{$pm->id}\n";
    				echo "{$pm->address}\n";
    				foreach ( $pm->AddressDetails as $pm1 )
					{
						foreach ( $pm1->Country as $pm2 )
						{
    						echo "{$pm2->CountryName}\n";
    						echo "{$pm2->CountryNameCode}\n";
    					}
    				}
				}

10.4151544
48.4297427
$q = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=10.4151544,48.4297427&destinations=45.2078,-97.0929"; 

$json = file_get_contents($q); 

$details = json_decode($json, TRUE); 

echo "<pre>"; print_r($details); echo "</pre>"; 
*/
			//	$this->renderPartial('_view', array(
			//'dataProvider'=> 'b'), true, true);

	public function actionIndex()
	{
		$model=new GeoForm;
		$data = array();
        $data["myValue"] = "Content loaded";
		$this->render('index',array('model'=>$model, 'myValue'=>$data["myValue"], 'page' => 1));
	}


}
